package com.imdroid.carac.model;

/**
 * The modal of the team member
 * 
 */
public class TeamMember {
	/**
	 * The id the team member
	 */
	private int id;
	/**
	 * The display name
	 */
	private String DisplayName;
	/**
	 * The location - lon
	 */
	private float lon;
	/**
	 * The location - lat
	 */
	private float lat;
	/**
	 * The location - speed
	 */
	private float speed;
	/**
	 * The location - direct
	 */
	private float direct;
	/**
	 * The type of device 1-lite版本,2或其他-车机
	 */
	private String deviceType;
	/**
	 * if the user in the team;
	 */
	private boolean accpect;
	/**
	 * if the user is on line;
	 */
	private boolean onLine;

	/**
	 * time escape from last time;
	 */
	private Long updatedTime;

	/**
	 * get interval of member from last time
	 * 
	 * @return Long interval
	 */
	public Long getUpdatedTime() {
		return updatedTime;
	}

	/**
	 * set interval of member from last time
	 * 
	 * @param interval
	 */
	public void setUpdatedTime(Long updatedTime) {
		this.updatedTime = updatedTime;
	}

	/**
	 * Get the id of the member
	 * 
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * Set the id of user
	 * 
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Get the display name of user
	 * 
	 * @return the displayName
	 */
	public String getDisplayName() {
		return DisplayName;
	}

	/**
	 * Set the display of the user
	 * 
	 * @param displayName
	 *            the displayName to set
	 */
	public void setDisplayName(String displayName) {
		DisplayName = displayName;
	}

	/**
	 * Get if the user in the team
	 * 
	 * @return the accpect
	 */
	public boolean isAccpect() {
		return accpect;
	}

	/**
	 * Set if user in the team
	 * 
	 * @param accpect
	 *            the accpect to set
	 */
	public void setAccpect(boolean accpect) {
		this.accpect = accpect;
	}

	/**
	 * Get if the user is online
	 * 
	 * @return the onLine
	 */
	public boolean isOnLine() {
		return onLine;
	}

	/**
	 * Set if the user is online
	 * 
	 * @param onLine
	 *            the onLine to set
	 */
	public void setOnLine(boolean onLine) {
		this.onLine = onLine;
	}

	/**
	 * Get the longtitude
	 * 
	 * @return the lon
	 */
	public float getLon() {
		return lon;
	}

	/**
	 * Set the longtitude
	 * 
	 * @param lon
	 *            the lon to set
	 */
	public void setLon(float lon) {
		this.lon = lon;
	}

	/**
	 * Get the latitude
	 * 
	 * 
	 * 
	 * @return the lat
	 */
	public float getLat() {
		return lat;
	}

	/**
	 * Set the latitude
	 * 
	 * @param lat
	 *            the lat to set
	 */
	public void setLat(float lat) {
		this.lat = lat;
	}

	/**
	 * Get the speed
	 * 
	 * @return the speed
	 */
	public float getSpeed() {
		return speed;
	}

	/**
	 * Set the speed
	 * 
	 * @param speed
	 *            the speed to set
	 */
	public void setSpeed(float speed) {
		this.speed = speed;
	}

	/**
	 * @return the direct
	 */
	public float getDirect() {
		return direct;
	}

	/**
	 * @param direct
	 *            the direct to set
	 */
	public void setDirect(float direct) {
		this.direct = direct;
	}

	/**
	 * @return the deviceType
	 *  2 - 车机用户; 1-车机用户的Lite用户;3 - 访客
	 */
	public String getDeviceType() {
		return deviceType;
	}

	/**
	 * @param deviceType
	 *            the deviceType to set
	 */
	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}

	/**
	 * Get a new member from the http message
	 * 
	 * @param httpMessage
	 *            http message
	 * @return the new member object from the http message
	 */
	public static TeamMember getTeamMember(String httpMessage) {
		TeamMember member = new TeamMember();

		String[] item = httpMessage.split(":");
		// 用户姓名
		member.setId(Integer.parseInt(item[0]));
		// 用户名称
		member.setDisplayName(item[1]);
		// 是否在线
		if (item.length > 2)
			member.setOnLine(item[2].equals("1"));
		// 是否已接受
		if (item.length > 3)
			member.setAccpect(item[3].equals("1"));
		// 经纬度坐标
		if (item.length > 4)
			member.setLat(Float.parseFloat(item[4]));
		if (item.length > 5)
			member.setLon(Float.parseFloat(item[5]));
		if (item.length > 6)
			member.setSpeed(Float.parseFloat(item[6]));
		if (item.length > 7)
			member.setDirect(Float.parseFloat(item[7]));
		if (item.length > 8)
			member.setDeviceType(item[8]);

		// 记住当前更新的时间
		member.setUpdatedTime(System.currentTimeMillis());
		return member;
	}
}
